
package com.jf.cloud.distribution.controller.platform;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.distribution.dto.DistributionSpuBindDTO;
import com.jf.cloud.distribution.model.DistributionSpuBind;
import com.jf.cloud.distribution.service.DistributionSpuBindService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户商品绑定信息
 *
 * @author zz
 * @date 2021-08-09 14:14:07
 */
@RestController("platformDistributionSpuBindController")
@RequestMapping("/p/distribution_spu_bind")
@Tag(name = "用户商品绑定信息")
public class DistributionSpuBindController {

    @Autowired
    private DistributionSpuBindService distributionSpuBindService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取用户商品绑定信息列表" , description = "分页获取用户商品绑定信息列表")
    public ServerResponseEntity<PageVO<DistributionSpuBind>> page(@Valid PageDTO pageDTO) {
        PageVO<DistributionSpuBind> distributionSpuBindPage = distributionSpuBindService.page(pageDTO);
        return ServerResponseEntity.success(distributionSpuBindPage);
    }

    @GetMapping
    @Operation(summary = "获取用户商品绑定信息" , description = "根据id获取用户商品绑定信息")
    public ServerResponseEntity<DistributionSpuBind> getById(@RequestParam Long id) {
        return ServerResponseEntity.success(distributionSpuBindService.getById(id));
    }

    @PostMapping
    @Operation(summary = "保存用户商品绑定信息" , description = "保存用户商品绑定信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody DistributionSpuBindDTO distributionSpuBindDTO) {
        DistributionSpuBind distributionSpuBind = mapperFacade.map(distributionSpuBindDTO, DistributionSpuBind.class);
        distributionSpuBind.setId(null);
        distributionSpuBindService.save(distributionSpuBind);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新用户商品绑定信息" , description = "更新用户商品绑定信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody DistributionSpuBindDTO distributionSpuBindDTO) {
        DistributionSpuBind distributionSpuBind = mapperFacade.map(distributionSpuBindDTO, DistributionSpuBind.class);
        distributionSpuBindService.update(distributionSpuBind);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除用户商品绑定信息" , description = "根据用户商品绑定信息id删除用户商品绑定信息")
    public ServerResponseEntity<Void> delete(@RequestParam Long id) {
        distributionSpuBindService.deleteById(id);
        return ServerResponseEntity.success();
    }
}
